#! /usr/bin/env bash

# Copyright (c) 2024 XDream
# Copyright (c) 2024 bruceshu <shuhuan.bruce@gmail.com>
# 2024-6-30


set -e

BUILD_ROOT=`pwd`
FF_TARGET=$1

FF_ARCHS_ALL="armv7a arm64"

echo_archs() {
    echo "===================="
    echo "building $* archs"
    echo "===================="
}

print_help() {
    echo "sh build-android.sh [arch](armv7a|arm64|arm)"
    exit 1
}

case "$FF_TARGET" in
    "")
        echo_archs armv7a
        sh init-ffmpeg.sh $FF_TARGET
        sh tools/do-compile-ffmpeg.sh armv7a
    ;;
    armv7a|arm64)
        echo_archs $FF_TARGET
        sh init-ffmpeg.sh $FF_TARGET
        sh tools/do-compile-ffmpeg.sh $FF_TARGET
    ;;
    arm)
        echo_archs $FF_ARCHS_ALL
        sh init-ffmpeg.sh $FF_TARGET
        for ARCH in $FF_ARCHS_ALL
        do
            sh tools/do-compile-ffmpeg.sh $ARCH
        done
    ;;
    clean)
        echo "== clean ffmpeg =="
        for ARCH in $FF_ARCHS_ALL
        do
            if [ -d ffmpeg-$ARCH ]; then
                cd ffmpeg-$ARCH && git clean -xfd && cd -
            fi
        done
        echo "== rm output =="
        rm -rf $BUILD_ROOT/output
    ;;
    *)
        print_help
    ;;
esac



